<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
	
	    <base href="<%=basePath%>">
	    
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">    
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" type="text/css" href="<%=basePath%>/easyui/themes/default/easyui.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>/easyui/themes/icon.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>/css/index.css" />
		<title>index Page</title>
	
	</head>

	<body>
		<table id="comment"></table>
		
		<div id="comment_tool" style="padding:5px;">
			<div style="margin-bottom:5px;">
				<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="comment_tool.look();">查看</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-delete-new" plain="true" onclick="comment_tool.remove();">删除</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true"  onclick="comment_tool.reload();">刷新</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-redo" plain="true" onclick="comment_tool.redo();">取消选择</a>
			</div>
			
			<div style="padding:0 0 0 7px;color:#333;">
				<form id="search">
					<p>
						宾馆名称：<input type="text" class="textbox" name="hotelNameSearch" style="width:110px">
						发布者：<input type="text" class="textbox" name="userNameSearch" style="width:110px">
						评论内容：<input type="text" class="textbox" name="commentContext" style="width:110px">
						创建时间从：<input type="text" name="date_from" class="easyui-datebox" editable="false" style="width:110px">
						到：<input type="text" name="date_to" class="easyui-datebox" editable="false" style="width:110px">
						<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="comment_tool.search();">查询</a>
					</p>
				</form>
			</div>
		</div>
		
		<form id="comment_look" style="margin:0;padding:5px 0 0 50px;color:#333;">
			<p>
				评论宾馆：<input readonly="readonly" type="text" id="hotelName" name="hotelName"class="textbox" style="width:200px;">
			</p>
			<p>
				评论内容：<input readonly="readonly"  type="text" name="commentContext" id = "commentContext" class="textbox" style="width:200px;">
			</p>
			<p>
				评 论 者：<input readonly="readonly"  type="text" name="userName" id="userName" class="textbox" style="width:200px;">
			</p>
			<p>
				评论时间：<input readonly="readonly"  type="text" name="createTime" id = "createTime" class="textbox" style="width:205px;">
			</p>
		</form>
		<script type="text/javascript" src="<%=basePath%>/easyui/jquery.min.js"></script>
		<script type="text/javascript" src="<%=basePath%>/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="<%=basePath%>/easyui/locale/easyui-lang-zh_CN.js" ></script>
		<script type="text/javascript" >

		$(function () {
			
			$('#comment').datagrid({
				url : 'commentAction!getCommentList',
				fit : true,
				fitColumns : true,
				striped : true,
				rownumbers : true,
				border : false,
				pagination : true,
				pageSize : 10,
				pageList : [5, 10, 15, 20, 25],
				pageNumber : 1,
				sortName : 'commentId',
				sortOrder : 'desc',
				toolbar : '#comment_tool',
				remoteSort:	false,
				columns : [[
					{
						field : 'ck',
						title : '自动编号',
						align:'center',
						width : 100,
						checkbox : true,
					},
					{
						field : 'commentId',
						title : '评论编号',
						align:'center',
						width : 100,
						sortable : true,
						hidden : true
					},
					{
						field : 'hotelName',
						title : '评论宾馆',
						align:'center',
						width : 100,
						sortable : true,
						
					},
					{
						field : 'commentContext',
						title : '评论内容',
						width : 100,
						align:'center',
						sortable : true
					},
					{
						field : 'userName',
						title : '发布人',
						width : 100,
						align:'center',
						sortable : true
					},
					{
						field : 'createTime',
						title : '发布日期',
						width : 100,
						align:'center',
		  				sortable : true,
		  				formatter : function (value, rowData, rowIndex) {
							  if(value != null){
							  		var date = new Date(value);
							  	  	return  date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
							  }
						}
					}
				]]
			});
			
			$('#comment_look').dialog({
				width : 380,
				title : '查看订单信息',
				modal : true,
				closed : true,
				iconCls : 'icon-search',
			});
			
			
			$('#createTime').datebox({
				editable : false,
				formatter: function(date){ 
					 return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
				 }
			});
			
			//按钮事件
			comment_tool = {
				//刷新
				reload : function () {
					$('#comment').datagrid('reload');
				},
				//撤销
				redo : function () {
					$('#comment').datagrid('unselectAll');
					$('#search').form('clear');
				},
				//搜索
				search : function () {
					$('#comment').datagrid('load', {
						commentContext : $.trim($('input[name="commentContext"]').val()),
						hotelNameSearch : $.trim($('input[name="hotelNameSearch"]').val()),
						userNameSearch : $.trim($('input[name="userNameSearch"]').val()),
						date_from : $.trim($('input[name="date_from"]').val()),
						date_to : $.trim($('input[name="date_to"]').val()),
					});
				},
				//删除
				remove : function () {
					var rows = $('#comment').datagrid('getSelections');
					if (rows.length > 0) {
						$.messager.confirm('确定操作', '您正在要删除所选的记录吗？', function (flag) {
							if (flag) {
								var ids = [];
								for (var i = 0; i < rows.length; i ++) {
									ids.push(rows[i].commentId);
								}
								$.ajax({
									type : 'POST',
									url : 'commentAction!deleteComments',
									data : {
										commentIds : ids.join(',')
									},
									beforeSend : function () {
										$('#comment').datagrid('loading');
									},
									success : function (data) {
										if (data > 0) {
											$('#comment').datagrid('reload');
											$('#comment').datagrid('unselectAll');
											$.messager.show({
												title : '提示',
												msg : data + '个用户被删除成功！',
											});
										} else{
											$('#comment').datagrid('reload');
											$('#comment').datagrid('unselectAll');
											$.messager.alert('删除失败！', '未知错误导致失败，请重试！', 'warning');
										}
									}
								});
							}
						});
					} else {
						$.messager.alert('提示', '请选择要删除的记录！', 'info');
					}
				},
			    //编辑
				look : function () {
						var rows = $('#comment').datagrid('getSelections');
						if (rows.length > 1) {
							$.messager.alert('警告操作！', '查看记录只能选定一条数据！', 'warning');
						} else if (rows.length == 1) {
							$.ajax({
								url : 'commentAction!getCommentByCommentId',
								type : 'post',
								data : {
									commentId : rows[0].commentId
								},
								beforeSend : function () {
									$.messager.progress({
										text : '正在获取中...'
									});
								},
								success : function (data, response, status) {
									$.messager.progress('close');
									if (data) {
										var obj = $.parseJSON(data);
										var date = new Date(obj.createTime);
										var tt = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
										$('#createTime').datebox('setValue',tt);
										
										$('#comment_look').form('load', {
											userName       : obj.userName,
											hotelName      : obj.hotelName,
											commentContext   : obj.commentContext
										}).dialog('open');
									} else {
										$.messager.alert('获取失败！', '未知错误导致失败，请重试！', 'warning');
									}
								}
							});
						} else if (rows.length == 0) {
							$.messager.alert('警告操作！', '编辑记录至少选定一条数据！', 'warning');
						}
					}
			};
		});
		</script>
	</body>
</html>